/*
 * <p>Copyright® 2009-2022 东软 IT 实训中心版权所有。</p>
 */

package com.max.back.doctor.api;

import com.max.back.common.http.ResponseResult;
import com.max.back.doctor.form.PrescriptionForm;
import com.max.back.doctor.service.PrescriptionItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;

/**
 * @author 辛凤文 forward.seen@foxmail.com
 * @version 1.0
 * @description <p>
 * <code>PrescriptionItemApi</code>
 *
 * </p>
 * @time 2022/7/27 22:46
 * @see
 */
@RestController
@CrossOrigin
@RequestMapping("/prescriptionItem")
@Validated
public class PrescriptionItemApi {

    @Autowired
    private PrescriptionItemService prescriptionItemService;

    @PostMapping("/submitPrescriptionItems")
    public ResponseResult<Boolean> submitPrescriptionItems(@RequestBody
                                                           @Validated
                                                                   PrescriptionForm form) {
        Boolean result = prescriptionItemService.deleteAndCreatePrescriptionItems(form);
        return ResponseResult.getSuccessResult(result);
    }

    @GetMapping("/getSubmitPrescriptionItems")
    public ResponseResult<List<Map<String,Object>>> getSubmitPrescriptionItems(@NotBlank String prescriptionId){
        List<Map<String, Object>> submitPrescriptionItems = prescriptionItemService.getSubmitPrescriptionItems(prescriptionId);
        return ResponseResult.getSuccessResult(submitPrescriptionItems);
    }

}